import api from "/api/index.js";
const i18n = require("i18n/index")
var {
  appId
} = require("/config.js");
App({
  onLaunch() {
    i18n.getLanguage()
    const _this = this
    wx.login({
      success(res) {
         //登录
        if (res.code) {
          api.login({
            method: "POST",
            data: {
              code: res.code,
              appId: appId,
            },
          }).then((res) => {
            let user = res.data
            if(user.memberCard){
              wx.setStorageSync('memberCard', user.memberCard)
              user.memberCard = null
            }
            wx.setStorageSync('user', user)
            _this.todoList()
          })
        } else {
          console.log('登录失败！:::' + JSON.stringify(res.errMsg))
        }
      },
      fail: (res) => {
        console.log("获取登录凭证code失败！", res)
      }
    })
  },
  initLanguage(_this) {
    _this.setData({
      language: i18n.getLanguage(),
      $t: i18n.$t(),
    })
  },
  //获取待办事宜
  async todoList() {
    //支付订单
    api.payOrderTodo({
      method:"POST",
      data:{}
    }).then((res) => {
      wx.setStorageSync('todoList.payOrder', res.data)
    })
  },
  globalData: {
    userInfo: {},
    tabBar:{
      shopCarStatus: false//购物车状态
    }
  }
})